package com.leiduoduo.oms.controller;

import com.leiduoduo.oms.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class UserConsumerController {
    @Autowired
    RestTemplate restTemplate;

    private final static String REST_URL_PREFIX = "http://COM.LEIDUODUO.OMS.USERPROVIDER";

    @PostMapping("/addUser")
    public boolean addUser(User user){
        return restTemplate.postForObject(REST_URL_PREFIX+"/addUser",user,Boolean.class);
    }
    @GetMapping("/getUserById/{id}")
    public User getUserById(@PathVariable int id){
        return restTemplate.getForObject(REST_URL_PREFIX+"/getUserById/"+id,User.class);
    }
    @GetMapping("/getUserList")
    public List<User> getUserById(){
        return restTemplate.getForObject(REST_URL_PREFIX+"/getUserList",List.class);
    }
}
